package com.zlx.xBiaoShop.controller;


import com.zlx.xBiaoShop.entity.Result;
import com.zlx.xBiaoShop.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author admin
 * @Description goods 控制器层
 * @date 2020-12-05 17:52:12
 */
@RestController
@CrossOrigin
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    /*
        获取最新商品
     */
    @GetMapping("getNewGoods")
    public Result getNewGoods() {
        return new Result(goodsService.getNewGoods());
    }

    /*
        获取热门商品
     */
    @GetMapping("getHotGoods")
    public Result getHotGoods() {
        return new Result(goodsService.getHotGoods());
    }

    /*
        获取收藏的商品
     */
    @GetMapping("getAllFavorateGoods/{start}/{pageSize}/{userId}")
    public Result getAllFavorateGoods(@PathVariable Integer start, @PathVariable Integer pageSize, @PathVariable Integer userId) {
        return new Result(goodsService.findGoodsListByUserId(start, pageSize, userId));
    }

    /*
        获取所有的商品列表
     */
    @GetMapping("getGoodsPage/{start}/{pageSize}")
    public Result getGoodsPage(@PathVariable Integer start, @PathVariable Integer pageSize) {
        return new Result(goodsService.getGoodsPage(start, pageSize));
    }

    //    getGoodsPageByGoodsId
    @GetMapping("getGoodsPageByGoodsId/{start}/{pageSize}/{typeId}")
    public Result getGoodsPage(@PathVariable Integer start, @PathVariable Integer pageSize,
                               @PathVariable Integer typeId) {
        return new Result(goodsService.getGoodsPageByGoodsId(start, pageSize,typeId));
    }
    //增加浏览数
    @PutMapping("updateLookById/{id}/{look}")
    public Result updateLookById(@PathVariable Integer id,@PathVariable Integer look){
        goodsService.updateLookById(id,look);
        return new Result(true,"更新成功",null);
    }
    //搜索
    @GetMapping("getGoodsPageByGoodsName/{start}/{pageSize}/{goodsName}")
    public Result getGoodsPageByGoodsName(@PathVariable Integer start, @PathVariable Integer pageSize,
                               @PathVariable String goodsName) {
        return new Result(goodsService.getGoodsPageByGoodsName(start, pageSize,goodsName));
    }
}
